package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPowers;
import com.ruoyi.system.service.ISysPowersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职权信息Controller
 * 
 * @author ruoyi_Dzy
 * @date 2022-02-12
 */
@RestController
@RequestMapping("/system/powers")
public class SysPowersController extends BaseController
{
    @Autowired
    private ISysPowersService sysPowersService;

    /**
     * 查询职权信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:powers:list')")
    @ApiOperation("查询职权信息列表")
    @GetMapping("/list")
    public TableDataInfo list(SysPowers sysPowers)
    {
        startPage();
        List<SysPowers> list = sysPowersService.selectSysPowersList(sysPowers);
        return getDataTable(list);
    }

    /**
     * 导出职权信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:powers:export')")
    @Log(title = "职权信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysPowers sysPowers)
    {
        List<SysPowers> list = sysPowersService.selectSysPowersList(sysPowers);
        ExcelUtil<SysPowers> util = new ExcelUtil<SysPowers>(SysPowers.class);
        return util.exportExcel(list, "powers");
    }

    /**
     * 获取职权信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:powers:query')")
    @ApiOperation("获取职权信息详细信息")
    @ApiImplicitParam(name = "recNo", value = "职权信息编号", required = true, dataType = "String", paramType = "传职权信息编号")
    @GetMapping(value = "/{recNo}")
    public AjaxResult getInfo(@PathVariable("recNo") String recNo)
    {
        return AjaxResult.success(sysPowersService.selectSysPowersById(recNo));
    }

    /**
     * 新增职权信息
     */
    @PreAuthorize("@ss.hasPermi('system:powers:add')")
    @Log(title = "职权信息", businessType = BusinessType.INSERT)
    @ApiOperation("新增职权信息")
    @ApiImplicitParam(name = "sysPowers", value = "职权信息对象", required = true, dataType = "SysPowers", paramType = "传职权信息对象")
    @PostMapping
    public AjaxResult add(@RequestBody SysPowers sysPowers)
    {
        return toAjax(sysPowersService.insertSysPowers(sysPowers));
    }

    /**
     * 修改职权信息
     */
    @PreAuthorize("@ss.hasPermi('system:powers:edit')")
    @Log(title = "职权信息", businessType = BusinessType.UPDATE)
    @ApiOperation("修改职权信息")
    @ApiImplicitParam(name = "sysPowers", value = "职权信息对象", required = true, dataType = "SysPowers", paramType = "传职权信息对象")
    @PostMapping("/editList")
    public AjaxResult edit(@RequestBody SysPowers sysPowers)
    {
        return toAjax(sysPowersService.updateSysPowers(sysPowers));
    }

    /**
     * 删除职权信息
     */
    @PreAuthorize("@ss.hasPermi('system:powers:remove')")
    @Log(title = "职权信息", businessType = BusinessType.DELETE)
    @ApiOperation("删除职权信息")
    @ApiImplicitParam(name = "recNos", value = "职权信息编号数组", required = true, dataType = "String[]", paramType = "传职权信息编号数组")
    @GetMapping("/delete/{recNos}")
    public AjaxResult remove(@PathVariable String[] recNos)
    {
        return toAjax(sysPowersService.deleteSysPowersByIds(recNos));
    }
}
